package com.iot08.admin.controller;

import com.aliyun.tea.utils.StringUtils;
import com.iot08.admin.controller.base.BaseController;
import com.iot08.admin.service.BrokenScreenInsuranceService;
import com.iot08.admin.service.page.PageVO;
import com.iot08.admin.service.page.PageableImpl;
import com.iot08.common.entity.app.BrokenScreenInsurance;
import com.iot08.common.response.Response;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author cwj
 * @description
 * @date 2025/4/15 15:05
 **/
@Controller
@RequestMapping("brokenScreenInsurance")
public class BrokenScreenInsuranceController extends BaseController {

    @Resource
    private BrokenScreenInsuranceService brokenScreenInsuranceService;

    /**
     * @description 查询碎屏险的数据
     * @author cwj
     * @param [page]
     * @return org.springframework.web.servlet.ModelAndView
     * @date @time 2025/4/15 15:14
     **/
    @RequestMapping("list")
    public ModelAndView list(PageVO page, @RequestParam(value = "openid", required = false) String openid,
                             @RequestParam(value = "checkCode", required = false) String checkCode,
                             @RequestParam(value = "status", required = false) Integer status) {
        ModelAndView mv = new ModelAndView();
        Page<BrokenScreenInsurance> pages = brokenScreenInsuranceService.list(page,openid,checkCode,status);
        mv.addObject("brokenScreenInsurances", pages.getContent());
        if (pages.getPageable() instanceof PageableImpl) {
            PageableImpl pi = (PageableImpl) pages.getPageable();
            mv.addObject("page", pi.getPage());
        }
        mv.addObject("openid",openid);
        mv.addObject("checkCode",checkCode);
        mv.addObject("status",status);
        mv.addObject("butSet", getMyBut(page.getMenuId()));
        mv.setViewName("brokenScreenInsurance/broken_screen_insurance_list");
        return mv;
    }


    /**
     * @description 核销或撤销核销
     * @author cwj
     * @param [id, type]
     * @return org.springframework.web.servlet.ModelAndView
     * @date @time 2025/4/15 17:52
     **/
    @ResponseBody
    @RequestMapping(value = "cancelVerification", method = RequestMethod.POST)
    public Response<Object> cancelVerification(@RequestParam(required = true) String checkId, @RequestParam(required = true) Integer type) {
        if(StringUtils.isEmpty(checkId) || ObjectUtils.isEmpty(type)){
            return Response.failedResponse("请求参数不能为空");
        }
        return brokenScreenInsuranceService.cancelVerification(checkId,type, this.getSessionUser(), this.getRemortIP());
    }
}
